<!DOCTYPE html>
<html lang="en">

<head>
    <meta http-equiv="content-type" content="text/html; charset=UTF-8">
    <meta charset="utf-8">
    <title></title>
    <meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1, user-scalable=no">
    <meta name="description" content="">
    <meta name="author" content="">
    <!-- STYLESHEETS -->
    <!--[if lt IE 9]>
    <script src="../../js/flot/excanvas.min.js"></script>
    <script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
    <script src="http://css3-mediaqueries-js.googlecode.com/svn/trunk/css3-mediaqueries.js"></script><![endif]-->
    <link rel="stylesheet" type="text/css" href="../../css/cloud-admin.css">
    <link rel="stylesheet" type="text/css" href="../../css/themes/default.css" id="skin-switcher">
    <link rel="stylesheet" type="text/css" href="../../css/responsive.css">

    <link href="../../font-awesome/css/font-awesome.min.css" rel="stylesheet">
    <!-- file-input -->
    <link rel="stylesheet" type="text/css" href="../../js/file-input/fileinput.css"/>
    <!-- SELECT2 -->
    <link rel="stylesheet" type="text/css" href="../../js/select2/select2.min.css"/>
    <!-- UNIFORM -->
    <link rel="stylesheet" type="text/css" href="../../js/uniform/css/uniform.default.min.css"/>
    <!-- datatable -->
    <link rel="stylesheet" href="../../js/datatables/datatable.css">
    <!-- WIZARD -->
    <link rel="stylesheet" type="text/css" href="../../js/bootstrap-wizard/wizard.css"/>
    <link rel="stylesheet" href="../../js/datepicker/datepicker.css">
    <!-- FONTS
<link href='http://fonts.useso.com/css?family=Open+Sans:300,400,600,700' rel='stylesheet' type='text/css'>
-->
    <!-- JQUERY -->
    <script src="../../js/jquery/jquery-2.0.3.min.js"></script>
    <script src="../../js/common.js"></script>
</head>

<body>
<header class="navbar clearfix" id="header">
</header>

<!-- PAGE -->
<section id="page">
    <!-- SIDEBAR -->
    <div id="sidebar" class="sidebar">
        <div class="sidebar-menu nav-collapse">

            <!-- SIDEBAR MENU -->
            <ul>

            </ul>
            <!-- /SIDEBAR MENU -->
        </div>

    </div>
    <!-- /SIDEBAR -->
    <div id="main-content">

        <div class="container">
            <div class="row">
                <div id="content" class="col-lg-12">
                    <!-- PAGE HEADER-->
                    <div class="row">
                        <div class="col-sm-12">
                            <div class="page-header">
                                <!-- STYLER -->

                                <!-- /STYLER -->
                                <!-- BREADCRUMBS -->
                                <ul class="breadcrumb">
                                    <li>
                                        <i class="fa fa-home"></i>
                                        <a href="index.html">首页</a>
                                    </li>
                                    <li>
                                        <a href="#">商品管理</a>
                                    </li>
                                    <li>维护商品</li>
                                </ul>
                                <!-- /BREADCRUMBS -->

                            </div>
                        </div>
                    </div>
                    <!-- /PAGE HEADER -->
                    <!-- SAMPLE -->
                    <form id="form_coupon">
                        <div class="row col-md-12">
                            <div class="col-md-3" style="width: 25%;height:200px">
                                <div class="" style="text-align: center;margin-top:30%;font-size:24px;">基本信息</div>
                            </div>
                            <div class="col-md-9">
                                <div class="box border primary" style="height:260px">
                                    <div class="row mrg-bt10-right" style="margin-top:10px;">
                                        <label class="control-label col-md-3"><span class="required">*</span>优惠劵类型：</label>
                                        <div class="col-md-8 inline">
                                            <input type="radio" value="Postpone" name="couponType" checked/>顺延有效期
                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                    <div class="row mrg-bt10-right" style="margin-top:10px;">
                                        <label class="control-label col-md-3"><span class="required">*</span>优惠劵名称：</label>
                                        <div class="col-md-8 inline">
                                            <input type="text" class="form-control width-50" name="couponTitle" onfocus="this.select()"
                                                   onmouseover="this.onfocus()" placeholder="请输入优惠券名称" maxlength="50"/>
                                            <input type="hidden" name="id"/>
                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                    <div class="row mrg-bt10-right">
                                        <label class="control-label col-md-3"><span class="required">*</span>发放数量：</label>
                                        <div class="col-md-8 inline">
                                            <input type="text" class="form-control width-50" name="sendNum" onkeypress="return $.IsNum(event);"
                                                   onblur="return $.IsNaN(this);" onfocus="this.select()" onmouseover="this.onfocus()" placeholder="请输入发放数量"
                                                   maxlength="10"/>

                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                    <div class="row mrg-bt10-right">
                                        <label class="control-label col-md-3"><span class="required">*</span>面额：</label>
                                        <div class="col-md-8 inline">
                                            <input type="text" class="form-control width-50" name="faceValue" onkeypress="return $.IsNum(event);"
                                                   onblur="return $.IsNaN(this);" onfocus="this.select()" onmouseover="this.onfocus()" placeholder="请输入优惠券面额"
                                                   maxlength="10"/>

                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                    <div class="row mrg-bt10-right">
                                        <label class="control-label col-md-3"><span class="required">*</span>订单金额:</label>
                                        <div class="col-md-8 inline" style="text-align: left">
                                            <input type="radio" name="limit_group" checked="checked" value="0"/>不限金额</br>
                                            <div style="display: inline-flex"><input type="radio" name="limit_group" style="margin-top: 10px"
                                                                                     value="1"/><span>满</span>
                                                <input type="text" class="form-control" style="width:130px;margin-left:10px" name="limitValue"
                                                       onkeypress="return $.IsNum(event);" onblur="return $.IsNaN(this);" onfocus="this.select()"
                                                       onmouseover="this.onfocus()" placeholder="请输入订单金额" maxlength="10"/>
                                                <span>元可使用</span></div>
                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row col-md-12">
                            <div class="col-md-3" style="width: 25%;height:auto;">
                                <div class="" style="text-align: center;margin-top:30%;font-size:24px;">规则</div>
                            </div>
                            <div class="col-md-9">
                                <div class="box border primary" style="height:auto;">
                                    <div class="row mrg-bt10-right" style="margin-top:10px">
                                        <label class="control-label col-md-3"><span class="required">*</span>每人限领：</label>
                                        <div class="col-md-8 inline" style="text-align: left">
                                            <input type="text" class="form-control width-50" name="leadNum" onkeypress="return $.IsNum(event);"
                                                   onblur="return $.IsNaN(this);" onfocus="this.select()" onmouseover="this.onfocus()" placeholder="限领张数"
                                                   maxlength="2"/>
                                            (0表示不限张数)
                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                    <div class="row mrg-bt10-right" id="rangDate">
                                        <label class="control-label col-md-3">有效期：</label>
                                        <div class="col-md-6 inline " style="display:inline-flex">
                                            <input type="text" class="form-control width-50 bootstrap-datepicker" name="startDate" style="width:130px"/>-
                                            <input type="text" class="form-control width-50 bootstrap-datepicker" name="endDate" style="width:130px"/>
                                            <span class="error-span"></span>
                                        </div>

                                    </div>
                                    <div class="row mrg-bt10-right" id="rangDate">
                                        <label class="control-label col-md-3">顺延：</label>

                                        <div class="col-md-2 inline " style="display:inline-flex">
                                            <input type="text" class="form-control col-md-2" name="postponeDays" value="0"/><span>天</span>
                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                    <div class="row mrg-bt10-right">
                                        <label class="control-label col-md-3"></label>

                                        <div class="col-md-6 inline "><span style="color:red">有效期和顺延天数只能输入一种</span>
                                        </div>
                                    </div>
                                    <div class="row mrg-bt10-right">
                                        <label class="control-label col-md-3"><span class="required">*</span>可使用商品：</label>
                                        <div class="col-md-1 inline" style="width: 180px;text-align: left">
                                            <input type="radio" name="sceneType" checked="checked" value="ALL"/>全站通用
                                            <input type="radio" name="sceneType" value="Product"/>特定商品
                                            <input type="radio" name="sceneType" value="Brand"/>特定品牌
                                        </div>
                                    </div>
                                    <div class="row mrg-bt10-right productIds" style="height: 50px;display: none;">
                                        <label class="control-label col-md-3"><span class="required">*</span>商品id集：</label>
                                        <div class="col-md-8 inline">
                                            <textarea name="productIds" class="form-control width-50" style="width:280px;resize:none;height:50px"></textarea>
                                            (英文逗号相隔)
                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                    <div class="row mrg-bt10-right brand" style="height: 50px;display: none;">
                                        <label class="control-label col-md-3"><span class="required">*</span>选择品牌：</label>
                                        <div class="col-md-8 inline">
                                            <select id="brand_select" name="style" style="width: 50%">

                                            </select>
                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                    <div class="row mrg-bt10-right">
                                        <label class="control-label col-md-3"><span class="required">*</span>可领取用户：</label>
                                        <div class="col-md-1 inline" style="width: 210px;text-align: left">
                                            <input type="radio" name="receiveType" checked="checked" value="0"/>全部用户
                                            <input type="radio" name="receiveType" value='1'/>新用户
                                            <input type="radio" name="receiveType" value='2'/>女王
                                        </div>
                                    </div>
                                    <div class="row mrg-bt10-right">
                                        <label class="control-label col-md-3"><span class="required">*</span>适用平台：</label>
                                        <div class="col-md-1 inline" style="width: 210px;text-align: left">
                                            <input type="radio" name="salesPlatform" checked="checked" value="Yiigoo"/>壹果
                                            <input type="radio" name="salesPlatform" value='Yijiadian'/>壹家店

                                        </div>
                                    </div>
                                    <div class="row mrg-bt10-right">
                                        <label class="control-label col-md-3"><span class="required">*</span>前台显示：</label>
                                        <div class="col-md-1 inline" style="width: 210px;text-align: left">
                                            <input type="radio" name="showWeb" value='1'/>显示
                                            <input type="radio" name="showWeb" value='0' checked="checked"/>不显示
                                        </div>
                                    </div>
                                    <div class="row mrg-bt10-right">
                                        <label class="control-label col-md-3">使用说明：</label>
                                        <div class="col-md-8 inline">
                                            <textarea name="remark" class="form-control" style="width:280px;resize:none;"></textarea>
                                            <span class="error-span"></span>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="row" style="height: 30px;">
                            <div class="col-md-12" style="text-align: center;">
                                <div class="box ">
                                    <a href="#" class="btn btn-success config bt-submit" style="width: 100px">
                                        保存
                                    </a>
                                </div>
                            </div>
                        </div>
                    </form>
                    <!-- /SAMPLE -->

                    <div class="footer-tools">
								<span class="go-top">
								<i class="fa fa-chevron-up"></i> Top
							</span>
                    </div>
                </div>
                <!-- /CONTENT-->
            </div>
        </div>
    </div>
</section>
<!--/PAGE -->
<!-- JAVASCRIPTS -->
<!-- Placed at the end of the document so the pages load faster -->

<!-- BOOTSTRAP -->
<script src="../../bootstrap-dist/js/bootstrap.min.js"></script>

<!-- BLOCK UI -->
<script type="text/javascript" src="../../js/jQuery-BlockUI/jquery.blockUI.min.js"></script>
<!--bootbox-->
<script type="text/javascript" src="../../js/bootbox/bootbox.min.js"></script>
<!-- AUTOSIZE -->
<script type="text/javascript" src="../../js/autosize/jquery.autosize.min.js"></script>
<!-- spinner -->
<script src="../../js/spinner/spin.js"></script>
<!-- INPUT MASK -->
<script type="text/javascript" src="../../js/bootstrap-inputmask/bootstrap-inputmask.min.js"></script>

<!-- SELECT2 -->
<script type="text/javascript" src="../../js/select2/select2.min.js"></script>

<script type="text/javascript" src="../../js/datepicker/datepicker.js"></script>
<script src="../../js/jquery-validate/jquery.validate.min.js"></script>
<!-- COOKIE -->
<script type="text/javascript" src="../../js/jQuery-Cookie/jquery.cookie.min.js"></script>
<!-- CUSTOM SCRIPT -->
<script src="../../js/script.js"></script>

<script src="../../js/Sortable.min.js"></script>
<script>
    var AddCoupon = function () {
        var wizform = $('#form_coupon');
        var formValiInit = function () {
            wizform.validate({
                doNotHideMessage: true,
                errorClass: 'error-span',
                errorElement: 'span',
                rules: {
                    couponTitle: {
                        required: true
                    },
                    leadNum: {
                        required: true
                    },
                    sendNum: {
                        required: true
                    },
                    faceValue: {
                        required: true
                    },
                    limitPrice: {
                        required: true
                    },
                    productIds: {
                        required: true
                    }
                },
                highlight: function (element) {
                    $(element)
                        .closest('.row').removeClass('has-success').addClass('has-error');
                },

                unhighlight: function (element) {
                    $(element)
                        .closest('.row').removeClass('has-error');
                },
                success: function (label) {
                    if (label.attr("for") == "gender") {
                        label.closest('.row').removeClass('has-error').addClass('has-success');
                        label.remove();
                    } else {
                        label.addClass('valid')
                            .closest('.row').removeClass('has-error').addClass('has-success');
                    }
                }
            });
        };
        var loadBrand = function () {
            $.ajax({
                type: "get",
                url: App.getContextPath() + "admin/brand/searchBrandList.do?start=-1&limit=-1",
                async: true,
                success: function (result) {
                    if (result != null) {
                        var data = eval(result);
                        var option = "<option></option>";
                        $.each(data, function (index, item) {
                            option += "<option value='" + item.id + "'>" + item.brandName + "</option>";
                        });
                        $("#brand_select").empty().append(option).select2({
                            placeholder: "选择品牌"
                        });
                        $("#s2id_brand_select").addClass("width_100");
                    }
                }
            });
        };
        var saveCoupon = function () {
            if (wizform.valid() == false) return false;
            var limitValue = $("input[name=limitValue]").val();
            var limittype = $("[name=limit_group]:checked").val();
            if (limittype == "1" && (limitValue == "" || limitValue == "0")) {
                $("[name=limit_group]").closest('.row').removeClass('has-success').addClass('has-error');
                return false;
            }
            if (limittype == "0") {
                limitValue = 0;
            }
            //有效期和顺延天数不能同时输入

            var coupon = {};
            coupon.couponTitle = $("input[name=couponTitle]").val();
            coupon.sendNum = $("input[name=sendNum]").val();
            coupon.faceValue = $("input[name=faceValue]").val();
            coupon.limitPrice = limitValue;
            coupon.leadNum = $("input[name=leadNum]").val();
            coupon.startDate = $("input[name=startDate]").val();
            coupon.endDate = $("input[name=endDate]").val();
            coupon.remark = $("[name=remark]").val();
            coupon.postponeDays = $("[name=postponeDays]").val();
            coupon.couponType = $("[name=couponType]:checked").val();
            coupon.sceneType = $("[name=sceneType]:checked").val();
            if (coupon.sceneType == "Brand")
                coupon.productIds = $("#brand_select").val();
            else
                coupon.productIds = $("[name=productIds]").val();
            coupon.salesPlatform = $("[name=salesPlatform]:checked").val();
            coupon.receiveType = $("[name=receiveType]:checked").val();
            coupon.showWeb = $("[name=showWeb]:checked").val() == 1 ? true : false;
            if ((coupon.startDate != "" || coupon.endDate != "") && coupon.postponeDays != "" && coupon.postponeDays != "0") {
                $.alert("有效期和顺延天数不能同时输入");
                return false;
            }
            if (coupon.startDate == "" && coupon.endDate == "" && (coupon.postponeDays == "0" || coupon.postponeDays == "")) {
                $.alert("请输入有效期或顺延天数");
                return false;
            }
            if (coupon.productIds === "") {
                coupon.productIds = null;
            }else{
                coupon.productIds=coupon.productIds.split(",");
            }
            $.blockUI();
            $.ajax({
                type: "post",
                url: App.getContextPath() + "admin/coupon/addCoupon.do",
                contentType: 'application/json',
                data: JSON.stringify(coupon),
                async: true,
                success: function (result) {
                    $.unblockUI();
                    if (result.type == 'success') {
                        location.href = "coupon.html";
                    } else {
                        $.alert(result.content)
                    }
                }
            });
        };

        var validateIsAll = function () {
            $("input[name='limit_group'][value='0']").click();
            $("input[name='limitValue']").val('');
            if ($(this).val() == 'true') {
                $(".productIds").hide();
                $("input[name='limit_group'][value='1']").removeAttr('disabled');
                $("input[name='limitValue']").removeAttr('readonly');
            } else {
                $(".productIds").show();
                $("input[name='limit_group'][value='1']").attr('disabled', 'disabled');
                $("input[name='limitValue']").attr('readonly', 'readonly');
            }
        }

        return {
            init: function () {
                formValiInit();
                $.initDate($("#rangDate"), 0, 0);
                $("[name=startDate]").val("");
                $("[name=endDate]").val("");

                App.init();
                $(".bt-submit").click(saveCoupon);


                $("[name=couponType]").click(function () {
                    var v = $(this).val();
                    if (v == 'Postpone') {
                        $("[name=sendNum]").attr("disabled", "disabled");
                        $(".postponeCouponDiv").show();
                        $(".constantCouponDiv").hide();
                    } else {
                        $("[name=sendNum]").removeAttr("disabled");
                        $(".postponeCouponDiv").hide();
                        $(".constantCouponDiv").show();
                    }
                });
                $("input[name='sceneType']").click(function () {
                    var v = $(this).val();
                    switch (v) {
                        case "Product":
                            $(".productIds").show();
                            $(".brand").hide();
                            $("input[name='limit_group'][value='1']").attr('disabled', 'disabled');
                            $("input[name='limitValue']").attr('readonly', 'readonly');
                            break;
                        case "Brand":
                            loadBrand();
                            $(".brand").show();
                            $(".productIds").hide();
                            $("input[name='limit_group'][value='1']").removeAttr('disabled');
                            $("input[name='limitValue']").removeAttr('readonly');
                            break;
                        default:
                            $(".productIds").hide();
                            $(".brand").hide();
                            $("input[name='limit_group'][value='1']").removeAttr('disabled');
                            $("input[name='limitValue']").removeAttr('readonly');
                            break;
                    }

                });

            }
        }
    }();
    $(function () {
        $("#header").load("../head.html");
        AddCoupon.init();
    });
</script>

<!-- /JAVASCRIPTS -->
</body>

</html>